//
//  SafeViewController.m
//  Estate
//
//  Created by wangdongdong on 2017/9/29.
//  Copyright © 2017年 ttsx. All rights reserved.
//

#import "SegmentViewController.h"
#import "SafeBasicInformationViewController.h"
#import "SafeThreeTypePeopleVC.h"
#import "SafeSpecialTypeViewController.h"
#import "SafePatrolViewController.h"
#import "SafeDangerViewController.h"
#import "SafeConstructDeviceViewController.h"




#import "SafeViewController.h"

@interface SafeViewController ()


@end


@implementation SafeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"安全";
    self.view.backgroundColor = UIColorFromRGB(0xf2f2f2);

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(prompting)];

    [self setProjectInformation];
    
    // 创建暂存按钮
//    if (![self.typeStr isEqualToString:@"3"]) {
        [self createUI];
//    }
}

#pragma MARK - 提交
- (void)prompting {
    WDDAlertController *alertVC = [WDDAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    [LSUtility pushWDDAlertVC:alertVC withTitle:@"提示" andMessageStr:@"提交后此条记录不可修改, 是否确认提交?"];
    
    // 确认
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [self saveData];
    }];
    [alertVC addAction:sure];
    
    // 取消
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
    [alertVC addAction:cancel];
    [self presentViewController:alertVC animated:YES completion:nil];
}

// 通知(保存数据)
- (void)saveData {
    // 传参
    NSMutableDictionary *parameDic = [NSMutableDictionary dictionary];
    // 保存类型:提交
    [parameDic setObject:@"1" forKey:@"saveType"];
    // 添加安全类型
    [parameDic setObject:self.typeStr forKey:@"safeType"];
    
    // 通知(提交基本信息)
    [[NSNotificationCenter defaultCenter] postNotificationName:@"saveSafeBase" object:parameDic];
}

// 创建暂存按钮
- (void)createUI {
    // 暂存
    UIButton *submitBtn = [[UIButton alloc] init];
    [self.view addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-15);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.offset(190);
        make.height.offset(44);
    }];
    
    submitBtn.backgroundColor = UIColorFromRGB(0x25a498);
    submitBtn.layer.cornerRadius = 5;
    [submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [submitBtn setTitle:@"暂存" forState:UIControlStateNormal];
    [submitBtn addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
}

// 通知(暂存)
- (void)submit {
    // 传参
    NSMutableDictionary *parameDic = [NSMutableDictionary dictionary];
    // 保存类型:暂存
    [parameDic setObject:@"0" forKey:@"saveType"];
    // 添加安全类型
    [parameDic setObject:self.typeStr forKey:@"safeType"];
    // 通知(暂存基本信息)
    [[NSNotificationCenter defaultCenter] postNotificationName:@"saveSafeBase" object:parameDic];
}

// 项目信息
- (void)setProjectInformation {
    SegmentViewController *segmentViewVC = [[SegmentViewController alloc] init];
    segmentViewVC.height = DEF_SCREEN_HEIGHT-188;
    // 名称数组
    NSMutableArray *mTitleArr = [NSMutableArray array];
    // 子视图数组
    NSMutableArray *controlArray = [NSMutableArray array];
    
    // 基本信息
    SafeBasicInformationViewController *baseVC = [[SafeBasicInformationViewController alloc] init];
    baseVC.typeStr = self.typeStr;
    [mTitleArr addObject:@"基本信息"];
    [controlArray addObject:baseVC];
    
    // 检查信息
    UIViewController *checkVC;
    // 安全施工三类人员
    if ([self.typeStr isEqualToString:@"1"]) {
        checkVC = [[SafeThreeTypePeopleVC alloc] init];
    
    // 特种作业人员持证情况
    } else if ([self.typeStr isEqualToString:@"2"]) {
        checkVC = [[SafeSpecialTypeViewController alloc] init];
        
    // 监理安全巡查
    } else if ([self.typeStr isEqualToString:@"3"]) {
        checkVC = [[SafePatrolViewController alloc] init];
        
    // 危险性较大工程监理检查
    } else if ([self.typeStr isEqualToString:@"4"]) {
        checkVC = [[SafeDangerViewController alloc] init];
        
    // 施工设备进场验收监理核查
    } else if ([self.typeStr isEqualToString:@"5"]) {
        checkVC = [[SafeConstructDeviceViewController alloc] init];
    }
    [mTitleArr addObject:@"检查信息"];
    [controlArray addObject:checkVC];
    
    // 设置名称
    segmentViewVC.titleArray = mTitleArr;
    //设置子视图
    segmentViewVC.subViewControllers = controlArray;
    //设置选中字体颜色
    segmentViewVC.titleSelectedColor = [TTTheme defaultManger].defaultColor;
    // 标签栏背景色
    segmentViewVC.headViewBackgroundColor = [UIColor whiteColor];
    // 非选中状态下标签字体大小
    segmentViewVC.fontSize = 14.;
    // 选中下划线颜色
    segmentViewVC.bottomLineColor = [TTTheme defaultManger].defaultColor;
    
    segmentViewVC.buttonWidth = DEF_SCREEN_WIDTH / controlArray.count;
    segmentViewVC.buttonHeight = 44;
    [segmentViewVC initSegment];
    [segmentViewVC addParentController:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

